package com.lovo.middleman.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.lovo.middleman.bean.SupplierBean;
import com.lovo.middleman.mapper.SupplierMapper;
import com.lovo.middleman.service.ISupplierService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class SupplierServiceImpl extends ServiceImpl<SupplierMapper, SupplierBean> implements ISupplierService {

    @Autowired
    SupplierMapper supplierMapper;

    /**
     * 分页
     * @param curPage 当前页
     * @param pageSize  每页条数
     * @param supplierName 供应商名称
     * @param supplierBusinessScope 经营范围
     * @return
     */
    @Override
    public Page<SupplierBean> selectSupplierBeanPageItem(int curPage,
                                                         int pageSize,
                                                         String supplierName,
                                                         String supplierBusinessScope) {
        QueryWrapper<SupplierBean> queryWrapper = new QueryWrapper<>();
        if (supplierName != null && !"".equals(supplierName)) {
            queryWrapper.like("supplier_name", supplierName);
        }
        if (supplierBusinessScope != null && !"".equals(supplierBusinessScope)) {
            queryWrapper.like("supplier_business_scope", supplierBusinessScope);
        }
        return supplierMapper.selectPage(new Page<>(curPage, pageSize), queryWrapper);
    }

    /**
     * 根据id查询
     * @param id id
     * @return
     */
    @Override
    public SupplierBean selectSupplierBeanById(int id) {
        return supplierMapper.selectById(id);
    }


    /**
     * 先查询在修改
     * @param supplierBean 供应商对象
     */
    @Override
    public void updateSupplier(SupplierBean supplierBean) {

       supplierMapper.updateById(supplierBean);
    }

    /**
     * 添加
     * @param supplierBean 供应商对象
     */
    @Override
    public void addSupplier(SupplierBean supplierBean) {
        supplierMapper.insert(supplierBean);
    }

    /**
     * 导入表
     * @param supplierBeanList 供应商集合
     * @return
     */
    @Override
    public List<SupplierBean> addSupplier(List<SupplierBean> supplierBeanList) {


        return null;
    }
}
